package cn.edu.ccibe.exam16system.controller;

import cn.edu.ccibe.exam16system.entity.Dormitory;
import cn.edu.ccibe.exam16system.entity.DormitoryDto;
import cn.edu.ccibe.exam16system.service.DormitoryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class DormitoryController {

    @Resource
    private DormitoryService dormitoryService;

    @GetMapping("/dormitory")
    public String dormitory(@PathParam("page") Integer page, @PathParam("pageSize") Integer pageSize, Model model) {
        if (page == null) page = 1;
        if (pageSize == null) pageSize = 6;
        Page<Dormitory> pageInfo = new Page<>(page, pageSize);
        IPage<DormitoryDto> dormitoryPage = dormitoryService.pageDorm(pageInfo);
        model.addAttribute("dormitoryPage", dormitoryPage);
        return "dormitory";
    }
}
